home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Draw Editor / Source / Palette.h < prev    next >
Encoding:
Text File  |  1995-12-11  |  6.0 KB  |  220 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Palette.h
  3.  
  4.     Contains:    Palette Classes Definition
  5.  
  6.     Written by:    Dave Stafford
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. // -- Compiler/Preprocessor Switches --
  12.  
  13. #ifndef _PALETTE_
  14. #define _PALETTE_
  15.  
  16. #ifndef _COMPILERDEFS_
  17. #include "CompDefs.h"
  18. #endif
  19.  
  20. #ifndef _DRAWEDITORDEF_
  21. #include "DrawEditorDef.h"
  22. #endif
  23.  
  24. //=============================================================================
  25. // Forward Declarations
  26. //=============================================================================
  27. class DrawEditor;
  28.  
  29. //=============================================================================
  30. // Constants
  31. //=============================================================================
  32.  
  33. //=============================================================================
  34. // Enumerations
  35. //=============================================================================
  36.  
  37. enum {
  38.     kSelectionTool = 1,
  39.     kTextTool,
  40.     kRectangleTool,
  41.     kLineShapeTool,
  42.     kOvalTool,
  43.     kPolygonTool,
  44.     kInactiveTextTool
  45. };
  46.  
  47. //=============================================================================
  48. // CRGBColor
  49. //=============================================================================
  50. struct CRGBColor {
  51.  
  52.     // -- Construction --
  53.     CRGBColor( unsigned short redColor = 0,  
  54.                unsigned short greenColor = 0,  
  55.                unsigned short blueColor = 0  ) 
  56.                { red = redColor; green = greenColor; blue = blueColor; };
  57.                
  58.     CRGBColor(RGBColor& color) { red = color.red; green = color.green; blue = color.blue;  };
  59.     CRGBColor(RGBColor* color) { red = color->red; green = color->green; blue = color->blue;  };
  60.     CRGBColor(const CRGBColor& color ) { red = color.red; green = color.green; blue = color.blue;  };
  61.     CRGBColor& operator=(const RGBColor& rgb);
  62.  
  63.     unsigned short    red;                        /*magnitude of red component*/
  64.     unsigned short    green;                        /*magnitude of green component*/
  65.     unsigned short    blue;                        /*magnitude of blue component*/
  66. };
  67.  
  68.  
  69.  
  70. //=============================================================================
  71. // CPalette
  72. //=============================================================================
  73. class CPalette
  74. {
  75. public:
  76.     
  77.     // -- Init --
  78.     CPalette(DrawEditor* part);
  79.     
  80.     // Clients should call ClosePalette instead of destructing directly.
  81. protected:
  82.     virtual ~CPalette();
  83.  
  84. public:
  85.  
  86.     // -- Accessors --
  87.     virtual ODSShort GetSelectedPaletteItem() const;
  88.     virtual void SetSelectedPaletteItem(ODSShort paletteItem);
  89.     
  90.     // -- Palette --
  91.     virtual void GetPaletteRect(Rect* r) = 0;
  92.     virtual void TokenizePalettePresentation(Environment* ev, ODSession* session) = 0;
  93.     virtual void Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape) = 0;
  94.     virtual    ODBoolean     DoMouseDownInPalette(Environment* ev, 
  95.                                                 ODFrame* frame, 
  96.                                                 Point where, 
  97.                                                 ODSShort* chosenItem,
  98.                                                 ODBoolean changePalette) = 0;
  99.     
  100.     // -- Window --
  101.     virtual void CreatePalette(Environment* ev);
  102.     void ClosePalette(Environment* ev);
  103.     void ShowPalette(Environment* ev, ODBoolean show);
  104.     ODBoolean IsShown(Environment* ev);
  105.                 
  106.     // -- Presentation --
  107.     ODTypeToken GetPresentation() const;
  108.     void SetPresentation(ODTypeToken presentation);
  109.  
  110. protected:
  111.  
  112.     // -- Window --
  113.     ODWindow* GetPaletteWindow(Environment* ev);
  114.  
  115. //----------------------------------------------------------------------------------------
  116. // Data Members
  117. //
  118. protected:
  119.  
  120.     ODSShort        fSelectedPaletteItem;
  121.     DrawEditor*        fDrawEditor;
  122.     ODTypeToken        fPresentation;
  123.     ODID            fODWindowID;
  124. };
  125.  
  126.  
  127. //=============================================================================
  128. // CColorPalette
  129. //=============================================================================
  130.  
  131. class CColorPalette : public CPalette
  132. {
  133. public:
  134.     
  135.     // -- Init --
  136.     CColorPalette(DrawEditor* part);
  137.     virtual ~CColorPalette();
  138.  
  139. public:
  140.     
  141.     // -- Palette --
  142.             void        GetColor(short colorIndex, CRGBColor* color) const;
  143.             ODSShort     NumberOfColors() const;
  144.                 
  145.             void         GetPaletteRect(Rect* r);
  146.             void         TokenizePalettePresentation(Environment* ev, ODSession* session);
  147.     
  148.     virtual    void         Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape);
  149.             
  150.     virtual    ODBoolean     DoMouseDownInPalette(Environment* ev, 
  151.                                                 ODFrame* frame, 
  152.                                                 Point where, 
  153.                                                 ODSShort* chosenItem = kODNULL,
  154.                                                 ODBoolean changePalette = kODTrue);
  155.                 
  156. //----------------------------------------------------------------------------------------
  157. // Data Members
  158. //
  159. private:
  160.     static const short kColorPaletteHeight;
  161.     static const short kColorPaletteWidth;
  162.     static const short kColorSwatchSize;
  163.     static const short kColorSwatchAreaOffset;
  164.  
  165.     short            fNumbersOfColors;
  166.     ODRect            fSavedInvalidRect;
  167.     CTabHandle        fColorTable;
  168. };
  169.  
  170.  
  171. //=============================================================================
  172. // CToolPalette
  173. //=============================================================================
  174.  
  175. class CToolPalette : public CPalette
  176. {
  177. public:
  178.     
  179.     // -- Init --
  180.     CToolPalette(DrawEditor* part);
  181.     virtual ~CToolPalette();
  182.  
  183. public:
  184.     
  185.     // -- Palette --
  186.     virtual void         CreatePalette(Environment* ev);
  187.     
  188.             void         GetToolRect(short tool, Rect* rect);
  189.             void         AdjustTextTool(Environment* ev);
  190.             
  191.     virtual void         ActivateTool(Environment* ev, ODSShort whichTool);
  192.     virtual void         InvalidateTool(Environment* ev, ODSShort whichTool);
  193.     virtual    ODBoolean     DoMouseDownInPalette(Environment* ev, 
  194.                                                 ODFrame* frame, 
  195.                                                 Point where, 
  196.                                                 ODSShort* chosenItem = kODNULL,
  197.                                                 ODBoolean changePalette = kODTrue);
  198.     virtual void         Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape);
  199.                 
  200.             void         GetPaletteRect(Rect* r);
  201.             void         TokenizePalettePresentation(Environment* ev, ODSession* session);
  202.     
  203.                 
  204. //----------------------------------------------------------------------------------------
  205. // Data Members
  206. //
  207. private:
  208.     static const short kToolPaletteHeight;
  209.     static const short kToolPaletteWidth;
  210.     static const short kPaletteBasePictureID;
  211.     static const short kToolCount;
  212.     static const short kToolSize;
  213.     static const short kToolOffset;
  214.  
  215.     ODBoolean        fTextToolActive;
  216.     PicHandle*        fToolPicts;
  217. };
  218.  
  219.  
  220. #endif